<?php
require 'common.inc.php';
//遍历获取所有邮箱管理模块下的信息
$result=$db->query("SELECT * FROM {$DT_PRE}email_user where pushstatus=3 or pushstatus=4  ORDER BY itemid"); while($user2 = $db->fetch_array($result)) {
	$list[]=$user2;
 }
//遍历微信表里的邮箱 
$result1 = $db->query("SELECT * FROM {$DT_PRE}weixin_user where pushemail=1 and (pushstatus=3 or pushstatus=4)  ORDER BY itemid ");
while($user1 = $db->fetch_array($result1)) {
	$list[]=$user1;
}
$curr_time = time();
sleep(rand(0,10));
       foreach($list as $a=>$user){
			$pushlist = pushlist($user,$curr_time);         //获取推送的查询列表
			if(!$pushlist || empty($user['filtercategory']) ){
				//echo  '=> nodata to push ......<br>';
				continue;
			} 
			if($user['pushemail']){
				$md5 = md5(uniqid());
				$DT['push_filename']        = 'html_push/push-'.$md5;
				$DT['push_email_filename']  = 'html_push/push-'.$md5.'-email';
				//生成html
				tohtml('push');
				$filename = $CFG['com_dir'] ? DT_ROOT.'/'.$DT['push_filename'].'.'.$DT['file_ext'] : DT_CACHE.'/index.inc.html';
			}
        
          /*****************************
         * 发送邮件
         * *************************/
         if($user['pushemail']){
           $emails =  explode(';',$user['email']);
            foreach ($emails as $email){
			  if($email){
				  echo '<br>pushemail===>'.$email.'</br>';
				$resultf=$db->query("select itemid,title,password from {$DT_PRE}fsemail_38 where status=3 and fs=0 order by itemid asc limit 1");
                $fsemail = $db->fetch_array($resultf);
				$title=$pushlist[0]['title'];
				$content = file_get_contents($DT['push_email_filename'].'.html');
				$sender = 'admin@china-hxzb.com';
                $DT['smtp_user'] = $fsemail['title'];
				$DT['smtp_pass'] = $fsemail['password'];
				$rs_send_mail = send_mail($email, $title, $content, $sender);
				if($i%10==0){
				$db->query("update {$DT_PRE}fsemail_38 set fs=1 where itemid=". $fsemail['itemid']);
				}
				$zs=$db->query("select * from {$DT_PRE}fsemail_38 where status=3 and fs=0");
                $sum = $db->fetch_array($zs);
				if(!$sum){
					$db->query("update {$DT_PRE}fsemail_38 set fs=0");
				}
				//发送失败
				if($rs_send_mail==0){
					$db->query("update {$DT_PRE}fsemail_38 set status=2 where itemid=".$fsemail['itemid']);
				}
			  }
			}
         }
    }

?>
